package com.cjj.controller;

import com.cjj.service.CommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/forum/comments")
public class CommentLikeController {
    
    @Autowired
    private CommentLikeService commentLikeService;
    
    /**
     * 点赞评论
     */
    @PostMapping("/{commentId}/like")
    public ResponseEntity<?> likeComment(@PathVariable Long commentId,
                                         @RequestParam Long userId) {
        commentLikeService.likeComment(commentId, userId);
        return ResponseEntity.ok("点赞成功");
    }
    
    /**
     * 取消点赞评论
     */
    @DeleteMapping("/{commentId}/like")
    public ResponseEntity<?> unlikeComment(@PathVariable Long commentId,
                                          @RequestParam Long userId) {
        commentLikeService.unlikeComment(commentId, userId);
        return ResponseEntity.ok("取消点赞成功");
    }
    
    /**
     * 获取评论点赞状态
     */
    @GetMapping("/{commentId}/like-status")
    public ResponseEntity<Boolean> getLikeStatus(@PathVariable Long commentId,
                                                @RequestParam Long userId) {
        boolean hasLiked = commentLikeService.hasLiked(commentId, userId);
        return ResponseEntity.ok(hasLiked);
    }
}